
package com.oren.util;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**  
* @description
* @author  wangshiwei  
* @date   2018年6月25日 下午4:53:48
    
*/
public final class CodeUtil {
	
	private static final Logger LOGGER=LoggerFactory.getLogger(CodeUtil.class);
	
	/**
	 * 将url编码
	 * @param source
	 * @return
	 */
	public static String encodeURL(String source) {
		String target;
		try {
			target=URLEncoder.encode(source,"UTF-8");
			
		} catch (UnsupportedEncodingException e) {
			LOGGER.error("encode url failure",e);
			throw new RuntimeException(e);
		}
		return target;
	}
	/**
	 * 解码
	 * @param source
	 * @return
	 */
	public static String decodeURL(String source) {
		String target;
		try {
			target=URLDecoder.decode(source,"UTF-8");
			
		} catch (UnsupportedEncodingException e) {
			LOGGER.error("encode url failure",e);
			throw new RuntimeException(e);
		}
		return target;
	}
	
}
